#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root) {
        vector<vector<int>> vv;
        if (root == nullptr) {
            return vv;
        }
        queue<TreeNode*> q;
        q.push(root);
        int LevelSize = 1;

        while (LevelSize > 0) {
            vector<int> v;
            while (LevelSize-- > 0) {
                TreeNode* cur = q.front();
                q.pop();
                v.push_back(cur->val);
                if (cur->left) {
                    q.push(cur->left);
                }
                if (cur->right) {
                    q.push(cur->right);
                }
            }
            vv.push_back(v);
            LevelSize = q.size();
        }

        return vv;
    }
};